﻿using Microsoft.VisualBasic;
using System.Drawing;
using iTextSharp.text.pdf;
using iTextSharp.text;
using Workbook = Aspose.Cells.Workbook;
using Aspose.Cells;
using PdfReader = iTextSharp.text.pdf.PdfReader;
using ThoughtWorks.QRCode.Codec;
using SkiaSharp;
using FlowCard.PrintCard.Models;
using System.Text;
using OfficeOpenXml;
namespace FlowCard.PrintCard.Helper
{
    internal class QRCodeHelper
    {
        /// <summary>
        /// 生成二维码图片
        /// </summary>
        /// <param name="content">要生成二维码的字符串</param>
        /// <param name="tempImagePath">需要保存的路径</param>
        protected internal static void CreateImage(string content, string tempImagePath)
        {
            int size = 50;  //二维码中每个小点的大小，值越大，像素越大

            //创建二维码生成类  
            QRCodeEncoder qrCodeEncoder = new QRCodeEncoder();
            //设置编码模式  
            qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE;
            //设置编码测量度  
            qrCodeEncoder.QRCodeScale = size;
            //设置编码版本  
            qrCodeEncoder.QRCodeVersion = 0;
            //设置编码错误纠正  
            qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M;
            //生成二维码图片  
            Bitmap image = qrCodeEncoder.Encode(content, Encoding.UTF8);

            //Bitmap image = CreateImgCode(content, size); //生成二维码图片
            image.Save(tempImagePath, System.Drawing.Imaging.ImageFormat.Png);
            image.Dispose();
        }


        /// <summary>  
        /// 生成二维码图片  
        /// <summary>  
        /// <param name="codeNumber">要生成二维码的字符串</param>       
        /// <param name="size">二维码每个颗粒大小尺寸</param>  
        /// <returns>二维码图片</returns>  
        protected internal static Bitmap CreateImgCode(string codeNumber, int size)
        {
            //创建二维码生成类  
            QRCodeEncoder qrCodeEncoder = new QRCodeEncoder();
            //设置编码模式  
            qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE;
            //设置编码测量度  
            qrCodeEncoder.QRCodeScale = size;
            //设置编码版本  
            qrCodeEncoder.QRCodeVersion = 0;
            //设置编码错误纠正  
            qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M;
            //生成二维码图片  
            Bitmap image = qrCodeEncoder.Encode(codeNumber);
            return image;
        }


    }
}
